﻿/**
 * ...
 * @author sminutoli
*/

import com.dmotiko.general.*
import com.dmotiko.prune.*
import mx.transitions.easing.Regular;
import mx.transitions.Tween;
import mx.utils.Delegate;
import mx.video.FLVPlayback;


class FashionSection extends Section
{
	private var section_listener:Function;
	private var flv:FLVPlayback;
	private var sun_listener:Function;
	
	private function initClip():Void {
		super.initClip();
		
		//_x = 250;
		//_y = 132;
		stop();	
		
		sun_listener = Delegate.create(this, sun_hidden);
		section_listener = Delegate.create( this, section_changed );
		Site.getApp().addEventListener( Site.SECTION_CHANGED, section_listener );
	}
	
	private function refreshData():Void {
		
		if ( !bShowed ) return;
		
		if ( data == FashionBar.VIDEO ) {
			
			gotoAndStop(2);
			super.initClip();
			show();
			
		} else {
			
			gotoAndStop(3);
			
		}
	}
	
	private function section_changed(e):Void 
	{
		if ( e.section == SiteSections.FASHION ) {
			Site.getApp().getClips().getSol().addEventListener( BaseClipEvent.CHANGED, sun_listener );
		} else {
			hide();
			Site.getApp().getClips().getFashionZoom().hide();
		}
	}
		
	private function sun_hidden():Void 
	{
		if ( Site.getApp().getSection() != SiteSections.FASHION ) return;
		Site.getApp().getClips().getSol().removeEventListener( BaseClipEvent.CHANGED, sun_listener );
		show();
	}
	
	private function showEnd():Void {
		super.showEnd();
		if ( data == FashionBar.VIDEO ) {
			gotoAndStop(2);
		}
		if( _currentframe == 2 ){
			registerTween( "videoFade", new Tween( flv, "_alpha", Regular.easeOut, 0, 100, 0.7, true ), false, true);
			
		}
	}
	private function hideEnd():Void {
		super.hideEnd();
		if( _currentframe == 2) {
			registerTween( "videoFade", new Tween( flv, "_alpha", Regular.easeOut, 100, 0, 0.7, true ));
			flv.stop();
		}
	}
	
	private function tweenFinished( key:String, tween:Tween):Void {
		super.tweenFinished( key, tween );
		switch(key) {
			case "videoFade":
			if( flv._alpha > 0 ) flv.play();
			break;
		}
	}
	
}